﻿using BLL;
using Model;
using System;
using Thksoft.Modal.Page;

namespace Thksoft.Modal
{
    public partial class EditBasisSettings : FormPage
    {
        private Qs_Base_SetBLL qsb = new Qs_Base_SetBLL();

        protected override void BindPage()
        {
            if (FORM_IFEDIT)
            {
                Qs_Base_Set model = qsb.GetModelById(Request.QueryString["ID"].ToString());

                txtName.Text = model.Set_name;
                txtValue.Text = model.Set_value;
                txtRemark.Text = model.REMARK;
            }
            else
            {
                txtName.Text = "";
                txtValue.Text = "";
                txtRemark.Text = "";
            }
        }

        protected override void SaveClick(object sender, EventArgs e)
        {
            Qs_Base_Set model = new Qs_Base_Set();

            if (string.IsNullOrEmpty(txtName.Text.ToString()))
            {
                MessageBox.Show(Page, "请输入设置名称");
                return;
            }
            if (string.IsNullOrEmpty(txtValue.Text))
            {
                MessageBox.Show(Page, "请输入设置值");
                return;
            }
            model.Set_name = txtName.Text.ToString();
            model.Set_value = txtValue.Text;
            model.REMARK = txtRemark.Text;

            if (FORM_IFEDIT)
            {
                model.Set_id = int.Parse(Request.QueryString["ID"].ToString());

                int count = qsb.UpdateModel(model, "");
                if (count > 0)
                {
                    MessageBox.Show(Page, "保存成功");
                    return;
                }
                else
                {
                    MessageBox.Show(Page, "保存失败");
                    return;
                }
            }
            else
            {
                int count = qsb.InsertModel(model, "");
                if (count > 0)
                {
                    MessageBox.Show(Page, "保存成功");
                    return;
                }
                else
                {
                    MessageBox.Show(Page, "保存失败");
                    return;
                }
            }
        }

        protected override void UpdateTitle()
        {
            if (FORM_IFEDIT)
            {
                MessageBox.ResponseScript(this, "FORM_UPDATE_TITLE(\"编辑基础设置\");");
            }
            else
            {
                MessageBox.ResponseScript(this, "FORM_UPDATE_TITLE(\"添加基础设置\");");
            }
        }

        //protected override void UpdateFormSize()
        //{
        //    if (FORM_IFEDIT)
        //    {
        //        MessageBox.ResponseScript(this, "FORM_SIZE(827,300);");
        //    }
        //    else
        //    {
        //        MessageBox.ResponseScript(this, "FORM_SIZE(900,300);");
        //    }

        //}
    }
}